package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.prd.config.IdGeneratorSnowflake;
import com.prd.config.LoginInterceptor;
import com.prd.dto.WorkInputRecordDTO;
import com.prd.dto.WorkOrderDTO;
import com.prd.dto.WorkPointRecordDTO;
import com.prd.dto.WorkReportDTO;
import com.prd.enums.*;
import com.prd.model.*;
import com.prd.mapper.WorkReportMapper;
import com.prd.service.WorkInputRecordService;
import com.prd.service.WorkOrderService;
import com.prd.service.WorkPointRecordService;
import com.prd.service.WorkReportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.util.CommonUtil;
import com.prd.util.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 工作报告数据表 服务实现类
 * </p>
 *
 * @author lizhaoyi
 * @since 2023-11-06
 */
@Service
@Slf4j
public class WorkReportServiceImpl extends ServiceImpl<WorkReportMapper, WorkReportDO> implements WorkReportService {

    @Autowired
    private IdGeneratorSnowflake idGeneratorSnowflake;

    private WorkPointRecordService workPointRecordService;
    private WorkInputRecordService workInputRecordService;
    private WorkReportMapper workReportMapper;
    private WorkOrderService workOrderService;

    public WorkReportServiceImpl(WorkPointRecordService workPointRecordService, WorkInputRecordService workInputRecordService, WorkReportMapper workReportMapper, WorkOrderService workOrderService) {
        this.workPointRecordService = workPointRecordService;
        this.workInputRecordService = workInputRecordService;
        this.workReportMapper = workReportMapper;
        this.workOrderService = workOrderService;
    }

    /**
     * 添加工作日报
     * @param workReportDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JsonData creatDayReport(WorkReportDTO workReportDTO) {

        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Long id = idGeneratorSnowflake.snowflakeId();
        //工作绩效
        List<WorkPointRecordDTO> workPointRecordDTOList = new ArrayList<>();
        if (workReportDTO.getWorkKPIPointRecordDTO() != null) {
            WorkPointRecordDTO workKPIPointRecordDTO = workReportDTO.getWorkKPIPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workKPIPointRecordDTO, WorkPointTypeEnum.WORK_KPI);
        }
        //工作汇报
        if (workReportDTO.getWorkReportPointRecordDTO() != null) {
            WorkPointRecordDTO workReportPointRecordDTO = workReportDTO.getWorkReportPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workReportPointRecordDTO, WorkPointTypeEnum.WORK_REPORT);
        }
        //异常及处理汇报
        if (workReportDTO.getWorkErrorPointRecordDTO() != null) {
            WorkPointRecordDTO workErrorPointRecordDTO = workReportDTO.getWorkErrorPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workErrorPointRecordDTO, WorkPointTypeEnum.ERROR_AND_HANDLE_REPORT);
        }
        //次日工作计划
        if (workReportDTO.getNextWorkPlanPointRecordDTO() != null) {
            WorkPointRecordDTO nextWorkPlanPointRecordDTO = workReportDTO.getNextWorkPlanPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, nextWorkPlanPointRecordDTO, WorkPointTypeEnum.NEXT_DAY_WORK_PLAN);
        }
        if (workPointRecordDTOList != null) {
            List<WorkPointRecordDO> workPointRecordDOList = CommonUtil.dtoListTransfer(workPointRecordDTOList, WorkPointRecordDO.class);
            boolean success = workPointRecordService.saveBatch(workPointRecordDOList);
            if (!success) {
                JsonData.buildError("新增工作绩效、工作汇报、异常及处理汇报、次日工作计划数据异常");
            }
        }
        //新增今日预算投入、实际投入、差异、次日预算投入 TODO 凭据后面需上传至OSS
        if (workReportDTO.getWorkInputRecordDTOList() != null) {
            boolean success = workInputRecordService.saveBatch(CommonUtil.dtoListTransfer(workReportDTO.getWorkInputRecordDTOList(), WorkInputRecordDO.class));
            if (!success) {
                JsonData.buildError("新增今日预算投入、实际投入、差异、次日预算投入数据异常");
            }
        }

        workReportDTO.setId(id);
        workReportDTO.setReportType(WorkReportTypeEnum.DAY_REPORT.getCode());
        workReportDTO.setCreatedBy(loginUser.getName());
        workReportDTO.setCreatedById(loginUser.getId());
        workReportDTO.setCreatedTime(LocalDateTime.now());

        int count = workReportMapper.insert(CommonUtil.dtoTransfer(workReportDTO, WorkReportDO.class));

        return count > 0 ? JsonData.buildSuccess() : JsonData.buildError("新增工作日报操作异常。");
    }


    /**
     * 查看日报详情
     * @param id
     * @return
     */
    @Override
    public JsonData dayDetail(Long id) {

        WorkReportDO workReportDO = workReportMapper.selectOne(new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getId, id)
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.DAY_REPORT.getCode()));

        if (workReportDO == null) {
            JsonData.buildError("工作日报不存在");
        }
        WorkReportDTO workReportDTO = CommonUtil.dtoTransfer(workReportDO, WorkReportDTO.class);
        //查询工作绩效、工作汇报、异常及处理汇报、次日工作计划数据
        List<WorkPointRecordDO> workPointRecordDOList = workPointRecordService.list(new LambdaQueryWrapper<WorkPointRecordDO>()
                .eq(WorkPointRecordDO::getWorkReportId, id)
                .in(WorkPointRecordDO::getType, Arrays.asList(WorkPointTypeEnum.WORK_KPI.getCode(), WorkPointTypeEnum.WORK_REPORT.getCode(), WorkPointTypeEnum.ERROR_AND_HANDLE_REPORT.getCode(), WorkPointTypeEnum.NEXT_DAY_WORK_PLAN.getCode())));
        Optional.ofNullable(workPointRecordDOList).ifPresent(o -> workReportDTO.setAllWorkPointRecordDTOList(CommonUtil.dtoListTransfer(workPointRecordDOList,WorkPointRecordDTO.class)));
        //查询今日预算投入、实际投入、差异、次日预算投入
        List<WorkInputRecordDO> workInputRecordDOList = workInputRecordService.list(new LambdaQueryWrapper<WorkInputRecordDO>()
                .eq(WorkInputRecordDO::getWorkReportId, id)
                .in(WorkInputRecordDO::getType, Arrays.asList(WorkInputTpyeEnum.PRE_INPUT.getCode(), WorkInputTpyeEnum.REAL_INPUT.getCode(), WorkInputTpyeEnum.DIFF_INPUT.getCode(), WorkInputTpyeEnum.NEXT_DAY_INPUT.getCode())));
        Optional.ofNullable(workInputRecordDOList).ifPresent(o -> workReportDTO.setWorkInputRecordDTOList(CommonUtil.dtoListTransfer(workInputRecordDOList,WorkInputRecordDTO.class)));


        return JsonData.buildSuccess(workReportDTO);
    }

    /**
     * 分页查询工作日报
     * @param page
     * @param size
     * @return
     */
    @Override
    public JsonData selectDayReportPage(int page, int size) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Page<WorkReportDO> pageInfo = new Page<>(page,size);
        Page<WorkReportDO> workReportDOPage = workReportMapper.selectPage(pageInfo, new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getCreatedById, loginUser.getId())
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.DAY_REPORT.getCode())
                .orderByDesc(WorkReportDO::getCreatedTime));
        return getJsonData(workReportDOPage);
    }

    /**
     * 分页查询工作周报
     * @param page
     * @param size
     * @return
     */
    @Override
    public JsonData selectWeekReportPage(int page, int size) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Page<WorkReportDO> pageInfo = new Page<>(page,size);
        Page<WorkReportDO> workReportDOPage = workReportMapper.selectPage(pageInfo, new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getCreatedById, loginUser.getId())
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.WEEK_REPORT.getCode())
                .orderByDesc(WorkReportDO::getCreatedTime));
        return getJsonData(workReportDOPage);
    }


    /**
     * 分页查询工作月报
     * @param page
     * @param size
     * @return
     */
    @Override
    public JsonData selectMonthReportPage(int page, int size) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Page<WorkReportDO> pageInfo = new Page<>(page,size);
        Page<WorkReportDO> workReportDOPage = workReportMapper.selectPage(pageInfo, new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getCreatedById, loginUser.getId())
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.MONTH_REPORT.getCode())
                .orderByDesc(WorkReportDO::getCreatedTime));
        return getJsonData(workReportDOPage);
    }

    /**
     * 添加工作周报
     * @param workReportDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JsonData creatWeekReport(WorkReportDTO workReportDTO) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Long id = idGeneratorSnowflake.snowflakeId();
        List<WorkPointRecordDTO> workPointRecordDTOList = new ArrayList<>();
        //本周工作总结
        if (workReportDTO.getWorkReportPointRecordDTO() != null) {
            WorkPointRecordDTO orderPointRecordDTO = workReportDTO.getWorkReportPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, orderPointRecordDTO,WorkPointTypeEnum.WEEK_WORK_REPORT);
        }
        //本周异常及处理总结
        if (workReportDTO.getWorkErrorPointRecordDTO() != null) {
            WorkPointRecordDTO workReportPointRecordDTO = workReportDTO.getWorkReportPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workReportPointRecordDTO,WorkPointTypeEnum.WEEK_ERROR_REPORT);
        }
        //下周工作计划
        if (workReportDTO.getNextWorkPlanPointRecordDTO() != null) {
            WorkPointRecordDTO workErrorPointRecordDTO = workReportDTO.getNextWorkPlanPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workErrorPointRecordDTO,WorkPointTypeEnum.NEXT_WEEK_WORK_PLAN);
        }
        if (workPointRecordDTOList != null) {
            List<WorkPointRecordDO> workPointRecordDOList = CommonUtil.dtoListTransfer(workPointRecordDTOList, WorkPointRecordDO.class);
            boolean success = workPointRecordService.saveBatch(workPointRecordDOList);
            if (!success) {
                JsonData.buildError("新增本周工作总结、本周异常及处理总结、下周工作计划数据异常");
            }
        }
        //新增本周预算投入、实际投入、差异、下周预算投入 TODO 凭据后面需上传至OSS
        if (workReportDTO.getWorkInputRecordDTOList() != null) {
            //前端传入类型，后端不需判断类型直接批量新增
            boolean success = workInputRecordService.saveBatch(CommonUtil.dtoListTransfer(workReportDTO.getWorkInputRecordDTOList(), WorkInputRecordDO.class));
            if (!success) {
                JsonData.buildError("新增本周预算投入、实际投入、差异、下周预算投入数据异常");
            }
        }

        workReportDTO.setId(id);
        workReportDTO.setReportType(WorkReportTypeEnum.WEEK_REPORT.getCode());
        workReportDTO.setCreatedBy(loginUser.getName());
        workReportDTO.setCreatedById(loginUser.getId());
        workReportDTO.setCreatedTime(LocalDateTime.now());

        int count = workReportMapper.insert(CommonUtil.dtoTransfer(workReportDTO, WorkReportDO.class));

        return count > 0 ? JsonData.buildSuccess() : JsonData.buildError("新增工作周报操作异常。");
    }

    /**
     * 查看周报详情
     * @param id
     * @return
     */
    @Override
    public JsonData weekDetail(Long id) {

        WorkReportDO workReportDO = workReportMapper.selectOne(new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getId, id)
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.WEEK_REPORT.getCode()));

        if (workReportDO == null) {
            JsonData.buildError("工作周报不存在");
        }
        WorkReportDTO workReportDTO = CommonUtil.dtoTransfer(workReportDO, WorkReportDTO.class);
        //查询本周工作总结、本周异常及处理总结、下周工作计划数据
        List<WorkPointRecordDO> workPointRecordDOList = workPointRecordService.list(new LambdaQueryWrapper<WorkPointRecordDO>()
                .eq(WorkPointRecordDO::getWorkReportId, id)
                .in(WorkPointRecordDO::getType, Arrays.asList(WorkPointTypeEnum.WEEK_WORK_REPORT.getCode(), WorkPointTypeEnum.WEEK_ERROR_REPORT.getCode(), WorkPointTypeEnum.NEXT_WEEK_WORK_PLAN.getCode())));
        Optional.ofNullable(workPointRecordDOList).ifPresent(o -> workReportDTO.setAllWorkPointRecordDTOList(CommonUtil.dtoListTransfer(workPointRecordDOList,WorkPointRecordDTO.class)));
        //查询本周预算投入、实际投入、差异、下周预算投入
        List<WorkInputRecordDO> workInputRecordDOList = workInputRecordService.list(new LambdaQueryWrapper<WorkInputRecordDO>()
                .eq(WorkInputRecordDO::getWorkReportId, id)
                .in(WorkInputRecordDO::getType, Arrays.asList(WorkInputTpyeEnum.WEEK_INPUT.getCode(), WorkInputTpyeEnum.WEEK_REAL_INPUT.getCode(), WorkInputTpyeEnum.WEEK_DIFF_INPUT.getCode(), WorkInputTpyeEnum.NEXT_WEEK_INPUT.getCode())));
        Optional.ofNullable(workInputRecordDOList).ifPresent(o -> workReportDTO.setWorkInputRecordDTOList(CommonUtil.dtoListTransfer(workInputRecordDOList,WorkInputRecordDTO.class)));


        return JsonData.buildSuccess(workReportDTO);
    }

    /**
     * 添加工作月报
     * @param workReportDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JsonData creatMonthReport(WorkReportDTO workReportDTO) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        Long id = idGeneratorSnowflake.snowflakeId();
        List<WorkPointRecordDTO> workPointRecordDTOList = new ArrayList<>();
        //本月工作总结
        if (workReportDTO.getWorkReportPointRecordDTO() != null) {
            WorkPointRecordDTO orderPointRecordDTO = workReportDTO.getWorkReportPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, orderPointRecordDTO,WorkPointTypeEnum.MONTH_WORK_REPORT);
        }
        //本月异常及处理总结
        if (workReportDTO.getWorkErrorPointRecordDTO() != null) {
            WorkPointRecordDTO workReportPointRecordDTO = workReportDTO.getWorkReportPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workReportPointRecordDTO,WorkPointTypeEnum.MONTH_ERROR_REPORT);
        }
        //下月工作计划
        if (workReportDTO.getNextWorkPlanPointRecordDTO() != null) {
            WorkPointRecordDTO workErrorPointRecordDTO = workReportDTO.getNextWorkPlanPointRecordDTO();
            setWorkPointList(loginUser, id, workPointRecordDTOList, workErrorPointRecordDTO,WorkPointTypeEnum.NEXT_MONTH_WORK_PLAN);
        }
        if (workPointRecordDTOList != null) {
            List<WorkPointRecordDO> workPointRecordDOList = CommonUtil.dtoListTransfer(workPointRecordDTOList, WorkPointRecordDO.class);
            boolean success = workPointRecordService.saveBatch(workPointRecordDOList);
            if (!success) {
                JsonData.buildError("新增本月工作总结、本月异常及处理总结、下月工作计划数据异常");
            }
        }
        //新增新增本月工作总结、本月异常及处理总结、下月工作计划 TODO 凭据后面需上传至OSS
        if (workReportDTO.getWorkInputRecordDTOList() != null) {
            //前端传入类型，后端不需判断类型直接批量新增
            boolean success = workInputRecordService.saveBatch(CommonUtil.dtoListTransfer(workReportDTO.getWorkInputRecordDTOList(), WorkInputRecordDO.class));
            if (!success) {
                JsonData.buildError("新增新增本月工作总结、本月异常及处理总结、下月工作计划数据异常");
            }
        }

        workReportDTO.setId(id);
        workReportDTO.setReportType(WorkReportTypeEnum.MONTH_REPORT.getCode());
        workReportDTO.setCreatedBy(loginUser.getName());
        workReportDTO.setCreatedById(loginUser.getId());
        workReportDTO.setCreatedTime(LocalDateTime.now());

        int count = workReportMapper.insert(CommonUtil.dtoTransfer(workReportDTO, WorkReportDO.class));

        return count > 0 ? JsonData.buildSuccess() : JsonData.buildError("新增工作月报操作异常。");
    }

    /**
     * 查看月报详情
     * @param id
     * @return
     */
    @Override
    public JsonData monthDetail(Long id) {
        WorkReportDO workReportDO = workReportMapper.selectOne(new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getId, id)
                .eq(WorkReportDO::getReportType, WorkReportTypeEnum.MONTH_REPORT.getCode()));

        if (workReportDO == null) {
            JsonData.buildError("工作月报不存在");
        }
        WorkReportDTO workReportDTO = CommonUtil.dtoTransfer(workReportDO, WorkReportDTO.class);
        //查询本月工作总结、本月异常及处理总结、下月工作计划数据
        List<WorkPointRecordDO> workPointRecordDOList = workPointRecordService.list(new LambdaQueryWrapper<WorkPointRecordDO>()
                .eq(WorkPointRecordDO::getWorkReportId, id)
                .in(WorkPointRecordDO::getType, Arrays.asList(WorkPointTypeEnum.MONTH_WORK_REPORT.getCode(), WorkPointTypeEnum.MONTH_ERROR_REPORT.getCode(), WorkPointTypeEnum.NEXT_MONTH_WORK_PLAN.getCode())));
        Optional.ofNullable(workPointRecordDOList).ifPresent(o -> workReportDTO.setAllWorkPointRecordDTOList(CommonUtil.dtoListTransfer(workPointRecordDOList,WorkPointRecordDTO.class)));
        //查询本月实际投入、实际投入、差异、下月预算投入
        List<WorkInputRecordDO> workInputRecordDOList = workInputRecordService.list(new LambdaQueryWrapper<WorkInputRecordDO>()
                .eq(WorkInputRecordDO::getWorkReportId, id)
                .in(WorkInputRecordDO::getType, Arrays.asList(WorkInputTpyeEnum.MONTH_INPUT.getCode(), WorkInputTpyeEnum.MONTH_REAL_INPUT.getCode(), WorkInputTpyeEnum.MONTH_DIFF_INPUT.getCode(), WorkInputTpyeEnum.NEXT_MONTH_INPUT.getCode())));
        Optional.ofNullable(workInputRecordDOList).ifPresent(o -> workReportDTO.setWorkInputRecordDTOList(CommonUtil.dtoListTransfer(workInputRecordDOList,WorkInputRecordDTO.class)));


        return JsonData.buildSuccess(workReportDTO);
    }

    /**
     * 增加抄送
     * @param id
     * @param userId
     * @return
     */
    @Override
    public JsonData addCCTo(Long id, String userId) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        WorkReportDO workReportDO = workReportMapper.selectOne(new LambdaQueryWrapper<WorkReportDO>()
                .eq(WorkReportDO::getId, id)
                .eq(WorkReportDO::getCreatedById, loginUser.getId()));
        if (workReportDO == null) {
            JsonData.buildError("工作报告不存在");
        }

        if (workReportDO.getCcId() != null) {
            List<String> ccList = Arrays.asList(workReportDO.getCcId().split(","));
            ccList.add(String.valueOf(userId));
            String ccString = ccList.toString();
            workReportDO.setCcId(ccString);

        }else {
            workReportDO.setCcId(String.valueOf(userId));
        }

        int count = workReportMapper.updateById(workReportDO);

        return count > 0 ? JsonData.buildSuccess() : JsonData.buildError("增加抄送人操作异常");
    }

    /**
     * 获取工作/任务导入列表
     * @return
     */
    @Override
    public JsonData getWorkOrderImportList() {

        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        List<WorkOrderDO> workOrderDOList = workOrderService.list(new LambdaQueryWrapper<WorkOrderDO>()
                .eq(WorkOrderDO::getCreatedWorkOrderId, loginUser.getId())
                .eq(WorkOrderDO::getOrderStatus, WorkOrderStatusEnum.FINISHED.getCode()));

        if (workOrderDOList != null) {
            return JsonData.buildSuccess(CommonUtil.dtoListTransfer(workOrderDOList, WorkOrderDTO.class));
        }

        return JsonData.buildSuccess(new ArrayList<>());
    }

    /**
     * 未达标/不合格
     * @param workReportDTO
     * @return
     */
    @Override
    public JsonData notStandard(WorkReportDTO workReportDTO) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        if (workReportDTO.getWorkOrderPointRecordDTO().getType().equals(WorkPointTypeEnum.NOT_STANDARD.getCode()) && workReportDTO.getWorkOrderPointRecordDTO()!=null) {
            JsonData.buildError("未达标/不合格传参为空");
        }
        WorkPointRecordDO workPointRecordDO = CommonUtil.dtoTransfer(workReportDTO.getWorkOrderPointRecordDTO(), WorkPointRecordDO.class);
        workPointRecordDO.setWorkReportId(workReportDTO.getId());
        workPointRecordDO.setCreatedBy(loginUser.getName());
        workPointRecordDO.setCreatedById(loginUser.getId());
        workPointRecordDO.setCreatedTime(LocalDateTime.now());
        workPointRecordDO.setType(WorkPointTypeEnum.NOT_STANDARD.getCode());
        workPointRecordDO.setTypeName(WorkPointTypeEnum.NOT_STANDARD.getMessage());
        workPointRecordDO.setModule(WorkMoudleTypeEnum.WORK_REPORT.getMessage());

        if (workPointRecordService.save(workPointRecordDO)) {
            JsonData.buildSuccess();
        }else {
            JsonData.buildError("未达标/不合格操作异常");
        }

        return null;

    }

    /**
     * 达标/合格
     * @param workReportDTO
     * @return
     */
    @Override
    public JsonData standard(WorkReportDTO workReportDTO) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        if (workReportDTO.getWorkOrderPointRecordDTO().getType().equals(WorkPointTypeEnum.STANDARD.getCode()) && workReportDTO.getWorkOrderPointRecordDTO()!=null) {
            JsonData.buildError("达标/合格传参为空");
        }
        WorkPointRecordDO workPointRecordDO = CommonUtil.dtoTransfer(workReportDTO.getWorkOrderPointRecordDTO(), WorkPointRecordDO.class);
        workPointRecordDO.setWorkReportId(workReportDTO.getId());
        workPointRecordDO.setCreatedBy(loginUser.getName());
        workPointRecordDO.setCreatedById(loginUser.getId());
        workPointRecordDO.setCreatedTime(LocalDateTime.now());
        workPointRecordDO.setType(WorkPointTypeEnum.STANDARD.getCode());
        workPointRecordDO.setTypeName(WorkPointTypeEnum.STANDARD.getMessage());
        workPointRecordDO.setModule(WorkMoudleTypeEnum.WORK_REPORT.getMessage());

        if (workPointRecordService.save(workPointRecordDO)) {
            JsonData.buildSuccess();
        }else {
            JsonData.buildError("达标/合格操作异常");
        }

        return null;
    }

    private JsonData getJsonData(Page<WorkReportDO> workReportDOPage) {
        Map<String,Object> pageMap = new HashMap<>(3);
        pageMap.put("total_record",workReportDOPage.getTotal());
        pageMap.put("total_page",workReportDOPage.getPages());
        pageMap.put("current_data", CommonUtil.dtoListTransfer(workReportDOPage.getRecords(), WorkReportDTO.class));

        return JsonData.buildSuccess(pageMap);
    }

    private void setWorkPointList(LoginUser loginUser, Long id, List<WorkPointRecordDTO> workPointRecordDTOList, WorkPointRecordDTO workKPIPointRecordDTO, WorkPointTypeEnum workPointTypeEnum) {
        workKPIPointRecordDTO.setWorkReportId(id);
        workKPIPointRecordDTO.setType(workPointTypeEnum.getCode());
        workKPIPointRecordDTO.setTypeName(workPointTypeEnum.getMessage());
        workKPIPointRecordDTO.setCreatedBy(loginUser.getName());
        workKPIPointRecordDTO.setCreatedById(loginUser.getId());
        workKPIPointRecordDTO.setCreatedTime(LocalDateTime.now());
        workPointRecordDTOList.add(workKPIPointRecordDTO);
    }


}
